package com.icow.wms.basic.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.icow.wms.basic.mapper.OrderTypeMapper;
import com.icow.wms.basic.domain.OrderType;
import com.icow.wms.basic.service.IOrderTypeService;

/**
 * orderTypeService业务层处理
 * 
 * @author bcs
 * @date 2024-08-21
 */
@Service
public class OrderTypeServiceImpl implements IOrderTypeService 
{
    @Autowired
    private OrderTypeMapper orderTypeMapper;

    /**
     * 查询orderType
     * 
     * @param id orderTypeID
     * @return orderType
     */
    @Override
    public OrderType selectOrderTypeById(Long id)
    {
        return orderTypeMapper.selectOrderTypeById(id);
    }

    /**
     * 查询orderType列表
     * 
     * @param orderType orderType
     * @return orderType
     */
    @Override
    public List<OrderType> selectOrderTypeList(OrderType orderType)
    {
        return orderTypeMapper.selectOrderTypeList(orderType);
    }

    /**
     * 新增orderType
     * 
     * @param orderType orderType
     * @return 结果
     */
    @Override
    public int insertOrderType(OrderType orderType)
    {
        return orderTypeMapper.insertOrderType(orderType);
    }

    /**
     * 修改orderType
     * 
     * @param orderType orderType
     * @return 结果
     */
    @Override
    public int updateOrderType(OrderType orderType)
    {
        return orderTypeMapper.updateOrderType(orderType);
    }

    /**
     * 批量删除orderType
     * 
     * @param ids 需要删除的orderTypeID
     * @return 结果
     */
    @Override
    public int deleteOrderTypeByIds(Long[] ids)
    {
        return orderTypeMapper.deleteOrderTypeByIds(ids);
    }

    /**
     * 删除orderType信息
     * 
     * @param id orderTypeID
     * @return 结果
     */
    @Override
    public int deleteOrderTypeById(Long id)
    {
        return orderTypeMapper.deleteOrderTypeById(id);
    }

    @Override
    public OrderType selectOrderTypeListByLoc(String startLoc, String endLoc) {
        if (startLoc == null || endLoc == null) {
            return null;
        }
        OrderType orderType = new OrderType();
        orderType.setStartLoc(startLoc);
        orderType.setEndLoc(endLoc);
        List<OrderType> orderTypes = orderTypeMapper.selectOrderTypeList(orderType);
        if (orderTypes != null && !orderTypes.isEmpty()) {
            return orderTypes.get(0);
        }
        OrderType temp = orderType;
        temp.setStartLoc("*");
        orderTypes = orderTypeMapper.selectOrderTypeList(temp);
        if (orderTypes != null && !orderTypes.isEmpty()) {
            return orderTypes.get(0);
        }
        temp = orderType;
        temp.setEndLoc("*");
        orderTypes = orderTypeMapper.selectOrderTypeList(temp);
        if (orderTypes != null && !orderTypes.isEmpty()) {
            return orderTypes.get(0);
        }
        temp = orderType;
        temp.setStartLoc("*");
        temp.setEndLoc("*");
        orderTypes = orderTypeMapper.selectOrderTypeList(temp);
        if (orderTypes != null && !orderTypes.isEmpty()) {
            return orderTypes.get(0);
        }
        return null;
    }
}
